package com.woniuxy.school.dietary.food.controller;


import com.woniuxy.commons.core.model.Result;
import com.woniuxy.commons.core.util.JwtUtil;
import com.woniuxy.school.dietary.food.entity.ProductsInfo;
import com.woniuxy.school.dietary.food.model.from.AddProductsInfoForm;
import com.woniuxy.school.dietary.food.service.ProductsInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吴彦祖
 * @since 2025年05月14日
 */
@RestController
@RequestMapping("/productsInfo")
@Api(tags = "餐品类别接口")
public class ProductsInfoController {
    @Autowired
    private ProductsInfoService productsInfoService;
    @PostMapping("/findProductsInfo")
    @ApiOperation(value = "用户查询所有餐品类别信息")
    public Result<List<ProductsInfo>> findProductsInfo(){
        return Result.getListResult(ProductsInfo.class).setCode(200).setMessage("查询成功").setData(productsInfoService.list());
    }
    @PostMapping("/addProductsInfo")
    @ApiOperation(value = "添加餐品类别信息")
    public Result addProductsInfo(@RequestBody AddProductsInfoForm addProductsInfoForm, @RequestHeader String token) throws Exception {
        String userId = JwtUtil.parseUserToken(token).get("userId").toString();
        productsInfoService.addProductsInfo(addProductsInfoForm,userId);
        return  Result.getResult().setCode(200).setMessage("添加成功") ;
    }
    @ApiOperation(value = "根据商家id查询餐品类别信息")
    @PostMapping("/findProductsInfoByStoreId")
    public Result<List<ProductsInfo>> findProductsInfoByStoreId(@RequestBody Long storeId){
        return Result.getListResult(ProductsInfo.class).setCode(200).setMessage("查询成功").setData(productsInfoService.findProductsInfoByStoreId(storeId));
    }
    @ApiOperation(value = "查询当前登录商家餐品类别信息")
    @PostMapping("/findMyProductsInfo")
    public Result<List<ProductsInfo>> findMyProductsInfo(@RequestHeader String token) throws Exception {
        String userId = JwtUtil.parseUserToken(token).get("userId").toString();
        return Result.getListResult(ProductsInfo.class).setCode(200).setMessage("查询成功").setData(productsInfoService.findProductsInfoByStoreId(Long.valueOf(userId)));
    }

}

